package com.briup.day14;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Objects;

public class Test_Student {
    public static void main(String[] args) {
        Student s1 = new Student("zs",20);
        Student s2 = new Student("ls",19);
        Student s3 = new Student("ww",22);
        Student s4 = new Student("tom",18);
        Student s5 = new Student("zs",20);

        //1.定义只能存储Student对象的集合
        Collection<Student> coll = new ArrayList<>();
//2.往集合中添加元素
        coll.add(s1);
        coll.add(s2);
        coll.add(s3);
        coll.add(s4);
        System.out.println(coll);
        boolean b1 = coll.contains(s5);
        System.out.println("-------------------------------------------------------------------------------------------");
        System.out.println(b1);//false
        System.out.println("-------------------------------------------------------------------------------------------");
        b1=coll.remove(s5);
        System.out.println(b1+"    after remove s5"+coll);
    }
}
class Student{
    private String name;
    private int age;
    public Student(String name,int age){
        this.name=name;
        this.age=age;
    }

    public Student() {
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof Student)) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}
